<template>
	<view>
		<input v-model="name" style="background-color: #999999" /><button @click="search()">搜索</button>
		
		<view  v-for="(item,i) in classes" :key="i">
			<text>{{item.name}}</text>
			<button @click="addClass(item.id)">加入</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				classes:{},
				name:""
			}
		},
		onShow() {
			this.search("");
		}
		,
		methods: {
			search(){
				var name=this.name;
				uni.request({
				method:"GET",
				url:this.requestUrl+"/ForeClass/findClass?name="+name,
				success:response=>{
					this.classes=response.data;
				}	
				})
			},
			addClass(classId){
				var userId=uni.getStorageSync("user").id;
				uni.request({
				method:"GET",
				url:this.requestUrl+"/ForeClass/addClass?userId="+userId+"&classId="+classId,
				success:response=>{
					if(response.data==1){
						uni.showToast({title: '加入班级成功！'});
					}else{
						uni.showToast({title: '请勿重复加入！'});
					}
				}	
				})
			}
		}
	}
</script>

<style>

</style>
